package com.lagou.edu.service.impl;

import com.lagou.edu.annot.Autowired;
import com.lagou.edu.annot.Service;
import com.lagou.edu.annot.Transactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;
import com.lagou.edu.utils.ConnectionUtils;
import com.lagou.edu.utils.TransactionManager;

/**
 * @author 应癫
 */
@Service("transferServiceImpl")
public class TransferServiceImpl implements TransferService {
    @Autowired
    private AccountDao accountDao;

    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money,boolean isError) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            if(isError) {
                int c = 1 / 0;
            }
            accountDao.updateAccountByCardNo(from);

    }
}
